package ru.gerunn.silent.message;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class MessageQueue {

	private Queue<Message> queue;

	public MessageQueue() {
		this.queue = new ConcurrentLinkedQueue<Message>();
	}

	synchronized public void add(Message message) {
		this.queue.add(message);
		this.notifyAll();
	}

	synchronized public Message get() throws InterruptedException {
		while (this.queue.isEmpty()) {
			this.wait();
		}
		return this.queue.remove();
	}

}
